package com.ejb;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import junit.framework.TestCase;

import org.junit.BeforeClass;
import org.junit.Test;

public class CalculatorIntegrationTestCase {

	private static Context namingContext;

	private static SimpleCalculatorBean calc;

	private static final String JNDI_NAME_CAL = "java:global/policenacorp.ejb.projeto1-ejb-1.0-SNAPSHOT/SimpleCalculatorBean";

	@BeforeClass
	public static void obtainProxyReferences() throws NamingException {
		namingContext = new InitialContext(null);
		calc = (SimpleCalculatorBean) namingContext.lookup(JNDI_NAME_CAL);
	}

	private void testAddition(final CalculatorCommonBusiness calc) {

		final int[] arguments = new int[] { 2, 3, 5 };

		final int expectedSum = 10;

		final int actualSum = calc.add(2, 3, 5);
		TestCase.assertEquals("Adicao nao retornou o resultado esperado.",
				expectedSum, actualSum);
	}

	@Test
	public void testAdditionsUsingBusinessReference() {
		this.testAddition(calc);
	}

}
